//
//  VBTabBar.swift
//  VBo
//
//  Created by 赵世得 on 2016/10/22.
//  Copyright © 2016年 Zh. All rights reserved.
//

import UIKit

class VBTabBar: UITabBar {
    var click: (() -> ())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setUpUI(){
        addSubview(btn)
    }
    
    @objc private func btnClick(){
    click?()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        let w = UIScreen.main.bounds.width * 0.2
        var index: CGFloat = 0
        for value in subviews {
            if value.isKind(of: NSClassFromString("UITabBarButton")!) {
                value.frame.size.width = w
                value.frame.origin.x = index * w
                index += 1
            }
            if index == 2 {
                index += 1
            }
            
        }
        btn.center.x = frame.size.width * 0.5
        btn.center.y = frame.size.height * 0.5
        
        
    }
    
    lazy var btn : UIButton = {
        let btn = UIButton(setImage: "tabbar_compose_icon_add", backImg: "tabbar_compose_button", target: self, action: #selector(btnClick))
        return btn
        
    }()
}

